package com.cms.recursoshumanos.ui.principal;

import com.cms.recursoshumanos.cache.UserInfoCache;
import com.cms.recursoshumanos.component.base.CustomMenuField;
import com.cms.recursoshumanos.container.ForegroundManager;
import com.cms.recursoshumanos.container.GridFieldManager;
import com.cms.recursoshumanos.container.TwoColumnFieldManager;
import com.cms.recursoshumanos.engine.ScreenEngine;
import com.cms.recursoshumanos.handler.BeneficiosAdministrativosScreenHandler;
import com.cms.recursoshumanos.ui.RecursosHumanosScreen;
import com.cms.recursoshumanos.utilities.Tool;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.XYEdges;
//import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BorderFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class PantallaNominaScreen extends RecursosHumanosScreen
{
    /**
     * Creates a new MyScreen object
     */
	//static Utileria tools = new Utileria();
	
	private GridFieldManager gridFieldManager;
	CustomMenuField item1,item2;
	
	public static PantallaNominaScreen instance = null;
	
	public static PantallaNominaScreen getInstance()
	{
		if (instance == null)
		{
			return new PantallaNominaScreen();
		}
		else
		{
			return instance;
		}
	}
	public PantallaNominaScreen() 
	{
		super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT );
		setContent();
		//setear_componenetes();
		
	}
	
	public void setContent() 
	{
		setTitle("Principal Nomina");
		
		ForegroundManager foreground = new ForegroundManager();
		
		TwoColumnFieldManager twoColumnManager = new TwoColumnFieldManager( Display.getWidth() / 2, USE_ALL_WIDTH );
        twoColumnManager.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager.setMargin( 10, 10, 10, 10 );
        twoColumnManager.setPadding( 6, 6, 6, 6 );
		
		gridFieldManager = new GridFieldManager(2, GridFieldManager.USE_ALL_HEIGHT|GridFieldManager.USE_ALL_WIDTH|GridFieldManager.FIELD_HCENTER|GridFieldManager.FIELD_VCENTER|GridFieldManager.FOCUSABLE);
		
		Font myFont = getFont().derive(Font.ITALIC, 6, Ui.UNITS_pt);
        gridFieldManager.setFont(myFont);
        
		item1 = new CustomMenuField("Beneficios LOTTT", 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Benefits.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Benefits_Focus.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				myFont, CustomMenuField.FIELD_VCENTER|CustomMenuField.FIELD_HCENTER) 
		{
			protected boolean navigationClick(int status, int time)
			{
				BeneficiosAdministrativosScreenHandler handler = new BeneficiosAdministrativosScreenHandler();
	   			handler.getBeneficiosAdministrativos(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   					UserInfoCache.getInstance().getUsuario().getPassword());
				return true;
			}
		};
		
		item2 = new CustomMenuField("Recibo", 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Receipt.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				Tool.getInstance().sizeImage(Bitmap.getBitmapResource("icons/Receipt_Focus.png"), 
						Tool.getInstance().getImgWidth()+30, 
						Tool.getInstance().getImgHeight()+30).getBitmap(), 
				myFont, 
				CustomMenuField.FIELD_VCENTER|CustomMenuField.FIELD_HCENTER) 
		{
			protected boolean navigationClick(int status, int time)
			{
				ScreenEngine.getInstance().goPantallaTipoRecibo();
				return true;
			}
		};
		
	
		
		item1.setMargin(30, 30, 30, 30);
		item2.setMargin(30, 30, 30, 30);

		gridFieldManager.add(item1);
		gridFieldManager.add(item2);
		
		twoColumnManager.add( gridFieldManager );
        
        foreground.add( twoColumnManager );
        add( foreground );

		int marginHeight = (Display.getHeight()-30-85-(85*2)-85)/3;
		if(marginHeight > 0)
			gridFieldManager.setMargin(marginHeight, 5, marginHeight, 5);
		else
			gridFieldManager.setMargin(5, 5, 5, 5);
		
		item1.setFocus();
	}
	
	/*private void setear_componenetes() 
	{
		setTitle("Principal Nomina");
		
		ForegroundManager foreground = new ForegroundManager();
		
		TwoColumnFieldManager twoColumnManager = new TwoColumnFieldManager( Display.getWidth() / 2, USE_ALL_WIDTH );
        twoColumnManager.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager.setMargin( 10, 10, 10, 10 );
        twoColumnManager.setPadding( 6, 6, 6, 6 );

        //vfm = new VerticalFieldManager(Field.FIELD_HCENTER); 
        
        boton_beneficio = new CustomButtonColored("BENEFICIO",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_beneficio.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			BeneficiosAdministrativosScreenHandler handler = new BeneficiosAdministrativosScreenHandler();
	   			handler.getBeneficiosAdministrativos(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   					UserInfoCache.getInstance().getUsuario().getPassword());
	       	} 
		}); 
        boton_recibo = new CustomButtonColored("RECIBO",ButtonField.CONSUME_CLICK | FIELD_HCENTER, Constant.COLOR_BUTTON_FOCUS); 

        boton_recibo.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			ListaReciboScreenHandler handler_5 = new ListaReciboScreenHandler();
	   			
	   			handler_5.getListaRecibo(
	   					UserInfoCache.getInstance().getUsuario().getNombre_Usuario(), 
	   					UserInfoCache.getInstance().getUsuario().getPassword());
	       	} 
		}); 
        

        twoColumnManager.add( boton_beneficio );
        
        
        foreground.add( twoColumnManager );
        add( foreground );
			
	}*/
	


}
